package com.kzd.btgame.main.home

import android.view.LayoutInflater
import androidx.fragment.app.Fragment
import com.kzd.btgame.callback.AppPagerAdapter
import com.kzd.btgame.databinding.ActivityHomeServiceBinding
import com.module.lemlin.app.OwnerStatusBar
import com.module.lemlin.owner.OwnerViewBindingActivity

class HomeServiceActivity : OwnerViewBindingActivity<ActivityHomeServiceBinding>() {

    companion object {
        private val tabs = arrayOf("今日开服", "即将开服", "历史开服")
    }

    private val mAppPagerAdapter: AppPagerAdapter by lazy {
        object : AppPagerAdapter(supportFragmentManager, tabs) {
            override fun fragment(position: Int): Fragment =
                HomeServiceFragment.newInstance(position)
        }
    }

    override val inflate: (LayoutInflater) -> ActivityHomeServiceBinding
        get() = ActivityHomeServiceBinding::inflate

    override fun initStatusBar(statusBar: OwnerStatusBar) {
        statusBar.run {
            addView = mViewBinding.flHomeServiceBar
        }
        super.initStatusBar(statusBar)
    }

    override fun initView() {
        mViewBinding.tabHomeServiceKind.apply {
            for (item in tabs) {
                addTab(newTab().setText(item))
            }
        }.setupWithViewPager(mViewBinding.vpHomeServiceBody.apply {
            adapter = mAppPagerAdapter
        })
    }
}